package gamegame;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.GridLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Point;
import java.awt.Dimension;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class PassCodeEnter extends JFrame
{
	private static final long serialVersionUID = 1710017;
	String entry;
	JPanel controlPanel;
	JButton[] numkeys;
	JButton enter, clear;
	JLabel thePasscode, spaceHold, spaceHold2;
	JTextField entryDisplay;
	public PassCodeEnter(String code)
	{
		super("Passcode Entry");
		spaceHold = new JLabel("");
		entry = "";
		numkeys = new JButton[10];
		controlPanel = new JPanel();
		enter = new JButton("Enter");
		enter.addActionListener(new ActionListener() { // anonymous class
			public void actionPerformed(ActionEvent e) {
				entry+="X";
				dispose();
			}
		});
		clear = new JButton("Clear");
		clear.addActionListener(new ActionListener() { // anonymous class
			public void actionPerformed(ActionEvent e) {
				entry="";
			}
		});
		entryDisplay = new JTextField("0000");
		thePasscode = new JLabel("          Just in case I forget, the password is "+code);
		/*setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS));
		controlPanel.setLayout(new GridLayout(4,3));//begin setup of grid numbers
		controlPanel.setSize(225,150);
		controlPanel.setVisible(true);
		controlPanel.setLocation(new Point(0,0));
		controlPanel.setMaximumSize(new Dimension(225,150));
		controlPanel.setMinimumSize(new Dimension(225,150));
		for(int i = 1; i < 10; i++)
		{
			numkeys[i] = new JButton(i+"");
			numkeys[i].addActionListener(new ActionListener() { // anonymous class
				public void actionPerformed(ActionEvent e) {
					entry+=e.getActionCommand();
				}
			});
			controlPanel.add(numkeys[i]);
		}
		numkeys[0] = new JButton(0+"");
		numkeys[0].addActionListener(new ActionListener() { // anonymous class
			public void actionPerformed(ActionEvent e) {
				entry+=e.getActionCommand();
			}
		});
		controlPanel.add(clear);
		controlPanel.add(numkeys[0]);
		controlPanel.add(enter);
		add(controlPanel);
		add(thePasscode);
		*/
		//test code starts
		setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		c.anchor = GridBagConstraints.PAGE_START;
		c.ipadx = 23;
		c.ipady = 10;
		for(int i = 1; i < 10; i++)
		{
			numkeys[i] = new JButton(i+"");
			numkeys[i].addActionListener(new ActionListener() { // anonymous class
				public void actionPerformed(ActionEvent e) {
					entry+=e.getActionCommand();
				}
			});
			c.gridx = (i - 1) % 3;
			c.gridy = (i - 1) / 3 + 1;
			add(numkeys[i], c);
		}
		
		c.gridx = 0;
		c.gridy = 4;
		c.ipadx = 0;
		add(clear, c);
		c.gridx = 1;
		numkeys[0] = new JButton(0+"");
		numkeys[0].addActionListener(new ActionListener() { // anonymous class
			public void actionPerformed(ActionEvent e) {
				entry+=e.getActionCommand();
			}
		});
		c.ipadx = 23;
		add(numkeys[0], c);
		c.ipadx = 0;
		c.gridx = 2;
		add(enter, c);
		c.gridx = 3;
		c.gridy = 1;
		c.gridheight = 2;
		c.weightx = 1.0;
		c.anchor = GridBagConstraints.LINE_START;
		add(thePasscode, c);
		c.weightx = 0.0;
		c.gridy = 0;
		c.gridx = 0;
		c.gridwidth = GridBagConstraints.REMAINDER;
		c.anchor = GridBagConstraints.LINE_START;
		c.gridheight = 1;
		c.gridwidth = 2;
		c.ipadx = 100;
		c.anchor = GridBagConstraints.PAGE_START;
		add(entryDisplay, c);
		c.weighty = 1.0;
		c.anchor = GridBagConstraints.PAGE_START;
		c.gridy = 5;
		add(spaceHold, c);
		c.weightx = 2.0;
		c.weighty = 0.0;
		c.gridwidth = GridBagConstraints.REMAINDER;
		c.gridx = 1;
		c.gridy = 0;
		spaceHold2 = new JLabel("");
		add(spaceHold2, c);
		//test code ends
		
	}
	public String toString()
	{
		return entry;
	}
}